#ifndef __FLATPAKBASE__H__
#define __FLATPAKBASE__H__

#include <FlatpakCommand.h>
#include <QDebug>


#define Arch(class, arg)    \
    class arch_##arg() {    \
        arch = #arg;        \
        return *this;       \
    }

#define Archs(class)  \
    Arch(class,aarch64)     \
    Arch(class,arm)         \
    Arch(class,i386)        \
    Arch(class,x86_64)      \

#define initCommand(class, cmd)   \
    class() { command = cmd;};

#define Cached(class)           \
    class cached() {            \
        args << "--cached";     \
        return *this;           \
    }

#define OstreeVerbose(class)            \
    class ostree_verbose() {            \
        args << "--ostree-verbose";     \
        return *this;                   \
    }

#define Columns2(class, column, arg)    \
    class column_##column() {           \
        columns << arg ;                \
        return *this;                   \
    }

#define Columns(class, column)          \
    Columns2(class, column, #column)


#define RemoteOrUri(class)                  \
    class remote_or_uri(QString arg) {      \
        remote = arg;                       \
        return *this;                       \
    }

#define CustomeFunc(class, function, arg)   \
    class function(QString arg) {           \
        arg = arg;                          \
        return *this;                       \
    }

#define Package(class)                      \
    class setPackage(QString arg) {         \
        package = arg;                      \
        return *this;                       \
    }

#define Runtime(class)                      \
    class setRuntime(QString arg) {         \
        runtime = arg;                      \
        return *this;                       \
    }

#define UserSystem(class)   \
    class User() {          \
        args << "--user";   \
        return *this;       \
    }                       \
                            \
    class System() {        \
        args << "--system"; \
        return *this;       \
    }                       \

#define RuntimeApp(class)   \
    class onlyRuntime() {   \
        args << "--runtime";\
        return *this;       \
    }                       \
                            \
    class onlyApp() {       \
        args << "--app";    \
        return *this;       \
    }                       \


#define Show(class, arg)        \
    class show_##arg() {        \
        args << "--show-" #arg ;\
        return *this;           \
    }

// #define Run()           \
//     QString run() { \
//                     \
//     }\

// #define ExecuteColumns()    \
//     if(columns.length()) {\
//         args << QString("--columns=%1").arg(columns.join(","));\
//     }

namespace Flatpak 
{
    class Base {

        protected:
            void run() {
                if (columns.length()) {
                    args << QString("--columns=%1").arg(columns.join(","));
                }
                if (!arch.isEmpty()) {
                    args << QString("--arch=%1").arg(arch);
                }
                if (!remote.isEmpty()) {
                    args << remote;
                }
                if (!package.isEmpty()) {
                    args << package;
                }
                if (!runtime.isEmpty()) {
                    args << QString("--app-runtime=%1").arg(runtime);
                }

                qDebug() << "Running:" << command << args;
            }

        protected:
            QString command = "";
            QStringList args;
            QStringList columns;
            QString arch = "";
            QString remote = "";
            QString package = "";
            QString runtime = "";
    };

    // Hide
    class List;
    class Info;

    // Builtin
    class FlatpakInstall;
    class FlatpakUpadte;
    class FlatpakUninstall;
    class FlatpakList;
    class FlatpakInfo;
    class FlatpakHistory;
    class FlatpakConfig;
    class FlatpakRepair;
    class FlatpakCreateUsb;

    // Finding Applications and runtimes
    class Search;

    // Running applications
    class Run;
    class Override;
    class MakeCurrent;
    class Enter;
    class Ps;
    class Kill;

    // Manage file access
    class Docuemnt;
    class DocumentExport;
    class DocuemntUnexport;
    class DocuemntInfo;

    // Manage dynamic permissions
    class Permissions;
    class PermissionRemove;
    class PermissionShow;
    class PermissionReset;

    // Manage remote respositories
    class Remotes;
    class RemoteAdd;
    class RemoteModify;
    class RemoteDelete;
    class RemoteList;
    class RemoteLs;
    class RemoteInfo;

    // Build applications
    class BuildInit;
    class Build;
    class BuildFinish;
    class BuildExport;
    class BuildBundle;
    class BuildImportBundle;
    class BuildSign;
    class BuildUpdateRepo;
    class BuildCommitFrom;
    class Repo;
    
}

#endif  //!__FLATPAKBASE__H__

/****************************************************************
-?                    build-sign            documents             --installation=       permission-list       --print-updated-env   remotes               uninstall 
build                 build-update-repo     document-unexport     --installations       permission-remove     ps                    remove                update 
build-bundle          config                enter                 kill                  permission-reset      remote-add            repair                upgrade 
build-commit-from     create-usb            --gl-drivers          list                  permissions           remote-delete         repo                  --user 
build-export          --default-arch        --help                make-current          permission-set        remote-info           run                   -v 
build-finish          document-export       history               mask                  permission-show       remote-list           search                --verbose 
build-import-bundle   document-info         info                  --ostree-verbose      pin                   remote-ls             --supported-arches    --version 
build-init            document-list         install               override              --print-system-only   remote-modify         --system     
****************************************************************/

/***************************************************************************************

Usage:
  flatpak [OPTION…] COMMAND

Builtin Commands:
 Manage installed applications and runtimes
  install                Install an application or runtime
  update                 Update an installed application or runtime
  uninstall              Uninstall an installed application or runtime
  mask                   Mask out updates and automatic installation
  pin                    Pin a runtime to prevent automatic removal
  list                   List installed apps and/or runtimes
  info                   Show info for installed app or runtime
  history                Show history
  config                 Configure flatpak
  repair                 Repair flatpak installation
  create-usb             Put applications or runtimes onto removable media

 Finding applications and runtimes
  search                 Search for remote apps/runtimes

 Running applications
  run                    Run an application
  override               Override permissions for an application
  make-current           Specify default version to run
  enter                  Enter the namespace of a running application
  ps                     Enumerate running applications
  kill                   Stop a running application

 Manage file access
  documents              List exported files
  document-export        Grant an application access to a specific file
  document-unexport      Revoke access to a specific file
  document-info          Show information about a specific file

 Manage dynamic permissions
  permissions            List permissions
  permission-remove      Remove item from permission store
  permission-set         Set permissions
  permission-show        Show app permissions
  permission-reset       Reset app permissions

 Manage remote repositories
  remotes                List all configured remotes
  remote-add             Add a new remote repository (by URL)
  remote-modify          Modify properties of a configured remote
  remote-delete          Delete a configured remote
  remote-ls              List contents of a configured remote
  remote-info            Show information about a remote app or runtime

 Build applications
  build-init             Initialize a directory for building
  build                  Run a build command inside the build dir
  build-finish           Finish a build dir for export
  build-export           Export a build dir to a repository
  build-bundle           Create a bundle file from a ref in a local repository
  build-import-bundle    Import a bundle file
  build-sign             Sign an application or runtime
  build-update-repo      Update the summary file in a repository
  build-commit-from      Create new commit based on existing ref
  repo                   Show information about a repo

Help Options:
  -h, --help              Show help options

Application Options:
  --version               Print version information and exit
  --default-arch          Print default arch and exit
  --supported-arches      Print supported arches and exit
  --gl-drivers            Print active gl drivers and exit
  --installations         Print paths for system installations and exit
  --print-updated-env     Print the updated environment needed to run flatpaks
  --print-system-only     Only include the system installation with --print-updated-env
  -v, --verbose           Show debug information, -vv for more detail
  --ostree-verbose        Show OSTree debug information


***************************************************************************************/